package com.kexio.user.dto;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 角色用户信息DTO
 * 
 * 用于返回拥有指定角色的用户信息
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RoleUserInfo implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 用户ID - UUID字符串
     */
    private String userId;
    
    /**
     * 用户名
     */
    private String username;
    
    /**
     * 昵称
     */
    private String nickname;
    
    /**
     * 部门ID
     */
    private String deptId;
    
    /**
     * 部门名称
     */
    private String deptName;
    
    /**
     * 用户状态：1-启用，0-禁用
     */
    private Integer status;
    
    /**
     * 是否被锁定
     */
    private Boolean isLocked;
    
    /**
     * 角色分配时间
     */
    private LocalDateTime assignedAt;
    
    /**
     * 角色分配者ID
     */
    private String assignedBy;
    
    /**
     * 角色分配者名称
     */
    private String assignedByName;
    
    /**
     * 最后登录时间
     */
    private LocalDateTime lastLoginTime;
    
    // ==================== 构造函数 ====================
    
    public RoleUserInfo() {}
    
    public RoleUserInfo(String userId, String username, String nickname) {
        this.userId = userId;
        this.username = username;
        this.nickname = nickname;
    }
    
    // ==================== 便捷方法 ====================
    
    /**
     * 判断用户是否为启用状态
     */
    public boolean isEnabled() {
        return Integer.valueOf(1).equals(status);
    }
    
    /**
     * 判断用户是否被锁定
     */
    public boolean isUserLocked() {
        return Boolean.TRUE.equals(isLocked);
    }
    
    /**
     * 判断用户是否为活跃状态
     */
    public boolean isActive() {
        return isEnabled() && !isUserLocked();
    }
    
    /**
     * 判断是否有部门信息
     */
    public boolean hasDept() {
        return deptId != null && !deptId.trim().isEmpty();
    }
    
    /**
     * 获取用户状态描述
     */
    public String getStatusText() {
        if (isUserLocked()) {
            return "已锁定";
        } else if (!isEnabled()) {
            return "已禁用";
        } else {
            return "正常";
        }
    }
    
    // ==================== Getter/Setter ====================
    
    public String getUserId() {
        return userId;
    }
    
    public void setUserId(String userId) {
        this.userId = userId;
    }
    
    public String getUsername() {
        return username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    public String getNickname() {
        return nickname;
    }
    
    public void setNickname(String nickname) {
        this.nickname = nickname;
    }
    
    public String getDeptId() {
        return deptId;
    }
    
    public void setDeptId(String deptId) {
        this.deptId = deptId;
    }
    
    public String getDeptName() {
        return deptName;
    }
    
    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }
    
    public Integer getStatus() {
        return status;
    }
    
    public void setStatus(Integer status) {
        this.status = status;
    }
    
    public Boolean getIsLocked() {
        return isLocked;
    }
    
    public void setIsLocked(Boolean locked) {
        isLocked = locked;
    }
    
    public LocalDateTime getAssignedAt() {
        return assignedAt;
    }
    
    public void setAssignedAt(LocalDateTime assignedAt) {
        this.assignedAt = assignedAt;
    }
    
    public String getAssignedBy() {
        return assignedBy;
    }
    
    public void setAssignedBy(String assignedBy) {
        this.assignedBy = assignedBy;
    }
    
    public String getAssignedByName() {
        return assignedByName;
    }
    
    public void setAssignedByName(String assignedByName) {
        this.assignedByName = assignedByName;
    }
    
    public LocalDateTime getLastLoginTime() {
        return lastLoginTime;
    }
    
    public void setLastLoginTime(LocalDateTime lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }
    
    @Override
    public String toString() {
        return "RoleUserInfo{" +
                "userId=" + userId +
                ", username='" + username + '\'' +
                ", nickname='" + nickname + '\'' +
                ", deptId='" + deptId + '\'' +
                ", deptName='" + deptName + '\'' +
                ", status=" + status +
                ", isLocked=" + isLocked +
                ", assignedAt=" + assignedAt +
                ", assignedBy='" + assignedBy + '\'' +
                ", assignedByName='" + assignedByName + '\'' +
                ", lastLoginTime=" + lastLoginTime +
                '}';
    }
}
